home *** CD-ROM | disk | FTP | other *** search
/ ftp.mactech.com 2010 / ftp.mactech.com.tar / ftp.mactech.com / machack / Hacks95 / Aaron 1.0b3.sit / Aaron 1.0b3 / Aaron Source / INIT.c < prev    next >
Text File  |  1995-06-24  |  3KB  |  141 lines

  1. /*    Aaron © 1995 Gregory D. Landweber, ALL RIGHTS RESERVED    */
  2.     
  3. #include <Notification.h>
  4. //#include "GB.h"
  5. #include "ShowInitIcon.h"
  6. #include <A4Stuff.h>
  7.  
  8. void PatchFinder( void );
  9.  
  10. pascal void Response ( NMRecPtr myRequest );
  11. void Notice ( void );
  12. long runable ( void );
  13. void main ( void );
  14. void KeepMeAround ( short refNum );
  15.  
  16. /*
  17. pascal void Response ( NMRecPtr myRequest )
  18. {
  19.     NMRemove ( myRequest );
  20.     if ( myRequest->nmStr )
  21.         DisposHandle ( RecoverHandle ((Ptr)myRequest->nmStr) );
  22.     DisposPtr ( (Ptr)myRequest->nmResp );
  23.     DisposPtr ( (Ptr)myRequest );
  24. }
  25.  
  26. void Notice ()
  27. {
  28.     long            size, thePtr;
  29.     NMRecPtr        myRequest;
  30.     StringHandle    theString;
  31.     
  32.     if ( thePtr  = (long)NewPtrSys( size = (long)&Notice - (long)&Response ) ) {
  33.         BlockMove ( (Ptr)&Response, (Ptr)thePtr, (Size)size );    
  34.         myRequest = (NMRecPtr) NewPtrSys ( sizeof( NMRec ) );
  35.         myRequest->qType   = nmType;
  36.         myRequest->nmMark  = 0;
  37.         myRequest->nmIcon  = 0;
  38.         myRequest->nmSound = (Handle) -1;
  39.         if ( theString = GetString( -10240 ) ) {
  40.             DetachResource ((Handle)theString);
  41.             HLock ((Handle)theString);
  42.             myRequest->nmStr  = *theString;
  43.         }
  44.         else
  45.             myRequest->nmStr   = 0;
  46.         myRequest->nmResp  = NewNMProc(thePtr);
  47.         myRequest->nmRefCon = 0;
  48.         NMInstall (myRequest);
  49.     }
  50. }
  51. */
  52.  
  53. // 680x0 code only
  54.  
  55. /* Code to keep an INIT file opened at boot time around all the time, à la
  56.    SuitCase II et al. */
  57.  
  58. typedef struct _res_map res_map;
  59. typedef struct _res_map *res_map_ptr;
  60. typedef struct _res_map **res_map_handle;
  61.  
  62. struct _res_map {
  63.     long                void1;        /* Reserved */
  64.     long                void2;        /* Reserved */
  65.     long                void3;        /* Reserved */
  66.     long                void4;        /* Reserved */
  67.     res_map_handle    next_map;    /* Handle of next resource map */
  68.     short            refNum;        /* fRefNum for this file */
  69.     short            fileAttrs;        /* Resource file attributes for this file */
  70.     short            tlOffset;        /* Type List Offset from beginning of map */
  71.     short            nlOffset;        /* Name List Offset from beginning of map */
  72. };
  73.  
  74. void KeepMeAround ( short refNum )
  75. {
  76.     THz                saved_zone;
  77.     res_map_handle    map_copy;
  78.     res_map_handle    the_map;
  79.  
  80.     the_map = (res_map_handle)LMGetTopMapHndl();
  81.     
  82.     if ( (*the_map)->refNum == refNum ) {
  83.         map_copy = the_map;
  84.         LMSetTopMapHndl ( (Handle) (*the_map)->next_map );
  85.     }
  86.     else {
  87.         map_copy = (*the_map)->next_map;
  88.         while ( (*map_copy)->refNum != refNum ) {
  89.             the_map  = map_copy;
  90.             map_copy = (*the_map)->next_map;
  91.         }
  92.         (*the_map)->next_map = (*map_copy)->next_map;
  93.         the_map  = map_copy;
  94.     }
  95.  
  96.     saved_zone = GetZone();
  97.     SetZone ( LMGetSysZone() );
  98.     HandToHand ( (Handle *)&map_copy );
  99.     SetZone(saved_zone);
  100.     
  101.     DisposHandle((Handle)the_map);
  102.  
  103.     the_map = (res_map_handle)LMGetSysMapHndl();
  104.     while ( (*the_map)->next_map )
  105.         the_map = (*the_map)->next_map;
  106.     (*the_map)->next_map  = map_copy;
  107.     (*map_copy)->next_map = nil;
  108. }
  109.  
  110. long runable(void)
  111. {
  112.     SysEnvRec        the_environment;                /* Environment record to determine if Color QD is implemented    */
  113.  
  114.     SysEnvirons(1,&the_environment);                /* Have machine tell us the environment                            */
  115.     return (the_environment.hasColorQD && the_environment.systemVersion >= 0x0700);
  116. }
  117.  
  118. void main ( void )
  119. {
  120.     short        refNum;
  121.     
  122.     long    oldA4 = SetCurrentA4();
  123.  
  124.     refNum = CurResFile();
  125.     
  126.     if ( !Button() && runable() ) {
  127.         Handle    patches = GetResource ( 'PACH', 130 );
  128.         
  129.         if ( patches && *patches ) {
  130.             DetachResource ( patches );
  131.             KeepMeAround ( refNum );
  132.             ( ( void (*) ( short ) ) StripAddress ( *patches ) ) ( refNum );
  133.         }    
  134.         ShowInitIcon( -1000, true );
  135.     //    Notice();
  136.     }
  137.     else
  138.         ShowInitIcon( -1000, true );
  139.  
  140.     SetA4 ( oldA4 );
  141. }